<style>
    .xxpayPopupDiv .layui-form-label {
        width:120px !important;
        margin-left:1%;
    }
    .xxpayPopupDiv .layui-input-inline {
        width: 80% !important;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <div class="layui-tab-content">
                <form class="layui-form center">
                    <input type="hidden" id="id" name="id">
                    <div class="layui-form-item">
                        <label class="layui-form-label">产品域名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="domainUrl" id="domainUrl"  style="width: 30%" autocomplete="off" class="layui-input" placeholder="域名地址（http://或https://开头）" required lay-verify="domainUrl">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">风控状态</label>
                        <div class="layui-input-inline" >
                            <input type="radio" name="riskStatus" title="开启" value="1" checked />
                            <input type="radio" name="riskStatus" title="关闭" value="0" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">域名类型</label>
                        <div class="layui-input-inline" >
                            <input type="radio" name="domainType" title="仅支付宝打开" value="1" />
                            <input type="radio" name="domainType" title="仅获取支付宝用户ID" value="2" />
                            <input type="radio" name="domainType" title="都支持" value="3" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">应用ID</label>
                        <div class="layui-input-inline">
                            <input type="text" name="appId" id="appId" placeholder="应用ID" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">应用私钥</label>
                        <div class="layui-input-inline">
                            <textarea name="appPrivateKey" id="appPrivateKey" placeholder="请输入应用私钥" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">支付宝公钥</label>
                        <div class="layui-input-inline">
                            <textarea name="alipayPublicKey" id="alipayPublicKey" placeholder="请输入支付宝公钥" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">商户ID</label>
                        <div class="layui-input-inline">
                            <input type="text" name="mchId" id="mchId" placeholder="商户ID" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">域名状态</label>
                        <div class="layui-input-inline" >
                            <input type="radio" name="domainStatus" title="启用" value="1" checked />
                            <input type="radio" name="domainStatus" title="停止" value="0" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-inline">
                            <button type="button" class="layui-hide xxpayYesBtn" lay-submit="" lay-filter="update">保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    
    layui.use(['form','table','util','admin'],function(){
        var form = layui.form
        , $ = layui.$
        , admin = layui.admin
        , layer = layui.layer
        , view = layui.view
        , element = layui.element
        , table = layui.table;
        
        element.render('breadcrumb', 'breadcrumb'); //渲染导航信息

        var id = view.getOpenParams('id');
        admin.req({
            type: 'post',
            url: layui.setter.baseUrl + '/config/pay_domain/get',
            data: {
                id:id,
            },
            error: function(err){
                layer.alert(err);
            },
            success: function(res){
                if(res.code == 0){
                    $("#id").val(res.data.id);
                    $("#domainUrl").val(res.data.domainUrl);
                    $("input[name='riskStatus'][value='"+res.data.riskStatus+"']").attr("checked",true);
                    $("input[name='domainType'][value='"+res.data.domainType+"']").attr("checked",true);
                    $("#appId").val(res.data.appId);
                    $("#appPrivateKey").val(res.data.appPrivateKey);
                    $("#alipayPublicKey").val(res.data.alipayPublicKey);
                    $("#mchId").val(res.data.mchId);
                    $("input[name='domainStatus'][value='"+res.data.domainStatus+"']").attr("checked",true);
                    form.render();
                }
            }
        });

        /* 自定义验证规则 */
        form.verify({
            domainUrl: [/(http|https):\/\/([\w.]+\/?)\S*/, '必须以http,https开头,且需符合URL规范,检查格式是否正确']
        });

        form.on('submit(update)', function(data){
            admin.req({
                type: 'post',
                url: layui.setter.baseUrl + '/config/pay_domain/update', //模拟接口,
                data: data.field,
                error: function(err){layer.alert(err.msg,{title:"请求失败"})},
                success: function(res){
                    if(res.code == 0){
                        layer.alert(res.msg, {title: '保存成功'},function(index){
                            layer.closeAll(); //关闭所有弹层
                            layui.table.reload('tableReload'); //调用业务弹层外表格重新加载
                        });
                    }
                }
            });
            return false;
        });

    });
    
</script>
